package com.guanyong.dao;

import com.guanyong.model.SubjectModel;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by mxk on 2017/6/1.
 */
public interface ISubjectDaoMapper {



    @Select("SELECT * FROM t_ad_subject  where f_id=#{fId}")
    @ResultMap("SubjectResultMap")
    SubjectModel selectByPrimaryKey(String fId);

    @Select("SELECT *,(SELECT COUNT(*) FROM t_ad_videotosubject WHERE t_ad_subject.`f_id`=t_ad_videotosubject.`f_subjectid`) AS f_ct FROM t_ad_subject ")
    @ResultMap("SubjectResultMap")
    List<SubjectModel> selectAllSubjectList();

    @Select("SELECT t_ad_subject.* FROM t_ad_subject ,t_ad_videotosubject where f_videoid=#{fViode} and t_ad_subject.f_id=t_ad_videotosubject.f_subjectid")
    @ResultMap("SubjectResultMap")
    List<SubjectModel> selectViodeSubjectList(@Param("fViode")String fViode);


    @Select("SELECT *,(SELECT COUNT(*) FROM t_ad_videotosubject WHERE t_ad_subject.`f_id`=t_ad_videotosubject.`f_subjectid`) AS f_ct  FROM t_ad_subject where f_type=#{type} ")
    @ResultMap("SubjectResultMap")
    List<SubjectModel> selectAllSubjectByType(@Param("type") Integer type);


    @Insert("insert t_ad_subject (f_title,f_photo,f_desc,f_type) " +
            "values(#{subjectModel.fTitle},#{subjectModel.fPhoto}," +
            "#{subjectModel.fDesc},#{subjectModel.fType})")
    Integer AddSubject(@Param("subjectModel") SubjectModel subjectModel);



    Integer UpdateSubject(@Param("subjectModel") SubjectModel subjectModel);


    @Delete("delete from  t_ad_subject  where f_id=#{id}" )
    Integer DeleteSubject(@Param("id") Integer id);

    @Delete("delete from  t_ad_videotosubject  where f_subjectid=#{subject_id} and f_videoid=#{videoid}" )
    Integer DeleteSubjectVideo(@Param("subject_id")Integer subject_id,
                               @Param("videoid")String videoid);

    @Delete("delete from  t_ad_videotosubject  where  f_videoid=#{videoid}" )
    Integer DeleteToSubjectVideo(@Param("videoid")String videoid);

    @Insert("insert t_ad_videotosubject (f_videoid,f_subjectid) " +
            "values(#{videoid},#{fSubjectid})")
    int AddSubjectVideo(@Param("videoid")String videoid,
                        @Param("fSubjectid")Integer fSubjectid);
}
